﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace General.IRepository
{
    /// <summary>
    /// 公共方法接口基类
    /// </summary>
    /// <typeparam name="TEntity">对象</typeparam>
    public interface IRepository<TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// 新增对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TEntity Insert(TEntity entity);
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(TEntity entity);
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Delete(TEntity entity);
        /// <summary>
        /// 根据主键查询对象
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        TEntity Find(int Id);
        /// <summary>
        /// 返回对象
        /// </summary>
        /// <param name="keyValues"></param>
        /// <returns></returns>
        TEntity Find(params object[] keyValues);
        /// <summary>
        /// 返回所有记录
        /// </summary>
        /// <returns></returns>
        List<TEntity> FindAll();
        /// <summary>
        /// 根据条件查询多个对象
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        List<TEntity> Query(TEntity entity, string[] field);
        /// <summary>
        /// 根据条件查询多个对象，返回所有列
        /// </summary>
        /// <param name="where">条件参数字典</param>
        /// <returns></returns>
        List<TEntity> Query(Dictionary<string, object> where);
        /// <summary>
        /// 根据条件查询多个对象，返回部分例
        /// </summary>
        /// <param name="where">条件参数字典</param>
        /// <param name="field">需要返回的字段 例：空表示全部返回</param>
        /// <returns></returns>
        List<TEntity> Query(Dictionary<string, object> where, string[] field);

    }
}
